//首页
#include "index.h"
//7个窗口
#include <QPushButton>
#include <QDebug>
#include <QTimer>

void inline Collect(QPushButton *collect,QString ii){
    collect->setText(ii+"收藏");
}
void inline PhotoGraph(QPushButton *photo,QString ii){
    photo->setText(ii+"照片");
}
void inline CouldData(QPushButton *could,QString ii){
    could->setText(ii+"云数据");
}
void inline Mail(QPushButton *mail,QString ii){
   mail->setText(ii+"邮件");
}

Index::Index(QWidget *parent): QWidget(parent)
{
    Vbox=new QVBoxLayout(this);//垂直布局
    this->setLayout(Vbox);
    QFont font("HONOR Sans Text GBK");
    font.setWeight(12);
    this->setFont(font);
    QWidget *Startbox=new QWidget(this);//添加2个Widget框
    QWidget *Tastbox=new  QWidget(this);
   //2个窗口添加到垂直布局中
    Vbox->addWidget(Tastbox);
    Vbox->addWidget(Startbox);
    Vbox->setStretch(0,2);
    Vbox->setStretch(1,3);
    Tast_Hbox=new QHBoxLayout(Startbox);//2水平布局
    Start_Hbox=new QHBoxLayout(Tastbox);

    //状态框子框2
    QWidget *Start_message=new QWidget(Startbox);
    QWidget *Start_chart=new QWidget(Startbox);
    //设置布局和背景颜色
   // Start_chart->setStyleSheet("background-color:rgb(0,0,80);");
    Start_Hbox->addWidget(Start_message);
    Start_Hbox->addWidget(Start_chart);
    Start_Hbox->setStretch(0,2);
    Start_Hbox->setStretch(1,4);

    //实现状态框功能
     grid=new QGridLayout(Start_message);
     QPushButton *collect=new    QPushButton(Start_message);
     QPushButton *photograph=new QPushButton(Start_message);
     QPushButton *coulddata=new  QPushButton(Start_message);
     QPushButton *mail=new       QPushButton(Start_message);

      collect->setText("收藏 ");
      photograph->setText("图片 ");
      coulddata->setText("云数据 ");
      mail->setText("邮件 ");

  /*  NetData *net=NetData::GetNetWork();

    if(!net->IsLink())
    {
        qDebug()<<"网络连接错误"<<endl;
        return ;
    }
    net->Get(0);
    connect(net,&NetData::geted,this,[=](){
        QVector<QString> list=net->GetNuber();
        Collect(collect,list[0]);
        PhotoGraph(photograph,list[1]);
        CouldData(coulddata,list[2]);
        Mail(mail,list[3]);
    });
*/
     //设置布局和背景颜色
     collect->setStyleSheet("background-color:rgb(155,223,223);border-radius:20px;border:none;");
     photograph->setStyleSheet("background-color:rgb(200,59,0);border-radius:20px;border:none;");
     coulddata->setStyleSheet("background-color:rgb(50,205,50);border-radius:20px;border:none;");
     mail->setStyleSheet("background-color:rgb(190,188,223);border-radius:20px;border:none;");
    collect->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
    photograph->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
    coulddata->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
    mail->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
     grid->addWidget(collect,0,0);
     grid->addWidget(photograph,0,1);
     grid->addWidget(coulddata,1,0);
     grid->addWidget(mail,1,1);
     grid->setContentsMargins(10,0,10,15);

     //图表
       chart=new SplineChar(this);
       chart_Vbox=new QVBoxLayout(Start_chart);
       chart_Vbox->setContentsMargins(0,0,0,0);
       chart_Vbox->addWidget(chart->DisPlay());
       Start_chart->setLayout(chart_Vbox);



     //任务框子框3
     QWidget *Tast_message=new QWidget(Tastbox);
     QWidget *Tast_tast=new QWidget(Tastbox);
     QWidget *Tast_countChart=new QWidget(Tastbox);
     //加入布局和背景颜色
     Tast_Hbox->addWidget(Tast_tast);
     Tast_Hbox->addWidget(Tast_message);
     Tast_Hbox->addWidget(Tast_countChart);
     Tast_message->setStyleSheet("background-color:rgb(255,255,255);");
     Tast_tast->setStyleSheet("background-color:rgb(255,255,255);");
     Tast_countChart->setStyleSheet("background-color:rgb(255,255,255);");

     //实现任务栏
    Additem_tast(Tast_tast);
    Additem_message(Tast_message);
    Additem_countChart(Tast_countChart);


    qtime=new QTimer(this);
    qtime->start(1000);
    connect(qtime,&QTimer::timeout,this,[&](){
     static int x=0;
     static int y=0;
     y++;
     x++;
      chart->setChartData(x,y);
    });

}

Index::~Index(){
    qtime->stop();
}

void Index::Additem_tast(QWidget *Tast_tast)
{
    QListWidget *list_1=new QListWidget(Tast_tast);
    QVBoxLayout *tast_layout=new QVBoxLayout(Tast_tast);
    tast_layout->addWidget(list_1);

}

void Index::Additem_message(QWidget *Tast_message)
{
    QListWidget *list_2=new QListWidget(Tast_message);
    QVBoxLayout *message_layout=new QVBoxLayout(Tast_message);
     message_layout->addWidget(list_2);

}

void Index::Additem_countChart(QWidget *Tast_countChart)
{
    QListWidget *list_3=new QListWidget(Tast_countChart);
    QVBoxLayout *count_layout=new QVBoxLayout(Tast_countChart);
    count_layout->addWidget(list_3);
}
